package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskReportDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskReport;

@Repository("iCyberBaseTaskReportDao")
public class CyberBaseTaskReportDaoImpl implements ICyberBaseTaskReportDao {
	
	@Autowired
	private EntityDao entityDao;

	@Override
	public Long addReport(BCyberBaseTaskReport report) throws SQLException {
		if (report != null) {
			return this.entityDao.save(report);
		}
		return 0L;
	}
	
	@Override
	public void updateReport (BCyberBaseTaskReport report) throws SQLException {
		if (report != null) {
			this.entityDao.update(report);
		}
	}
	
	@Override
	public int deleteReport (String report) {
		if (report != null) {
			this.entityDao.deleteDetached(report);
			return 0;
		}
		return -1;
	}
	
	@Override
	public BCyberBaseTaskReport getReport (String reportId) {
		BCyberBaseTaskReport bReportSent = null;
		if (reportId != null) {
			Long id;
			try {
				id = Long.parseLong(reportId);
			} catch (Exception e) {
				return null;
			}
			bReportSent = this.entityDao.findById(id, BCyberBaseTaskReport.class);
		}
		return bReportSent;
	}
	
	@Override
	public BCyberBaseTaskReport getReportByCode (String code) throws SQLException {
		BCyberBaseTaskReport report = null;
		if (code != null) {
			report = this.entityDao.getObj(BCyberBaseTaskReport.class, " o.code=? ", new Object[]{code});
		}
		return report;
	}
	
	@Override
	public void batchInsert(List<BCyberBaseTaskReport> sentList) {
		this.entityDao.batchInsert(sentList);
	}
	
	@Override
	public PageData<BCyberBaseTaskReport> getReportList (int pageNum, int pageSize, String hql, Object[] params, LinkedHashMap<String, String> reportMap) throws SQLException {
		return this.entityDao.getPagingData(BCyberBaseTaskReport.class, pageNum, pageSize, hql, params, reportMap);
	}
	
	@Override
	public List getReportListByHql(int pageNum, int pageSize, String hql, Object[] params) throws SQLException {
		return this.entityDao.getPagingDataByHql(pageNum, pageSize, hql, params);
	}
}
